<?php

interface Configable 
{

	public function parse($code);
	public function set($key, $value);
	public function get($key);

}

class XmlConfig implements Configable 
{

	protected $store;

	public function parse($code) 
	{
		$this->store = simplexml_load_string($code);
	}

	public function set($key, $value) 
	{
		$this->store->{$key} = $value;
	}
	
	public function get($key) 
	{
		return $this->store->{$key};
	}
	
}

class IniConfig implements Configable 
{

	protected $store;

	public function parse($code) 
	{
		$this->store = parse_ini_string($code);
	}

	public function set($key, $value) 
	{
		$this->store[$key] = $value;
	}
	
	public function get($key) 
	{
		return $this->store[$key];
	}
	
}

class PhpConfig implements Configable 
{

	protected $store;

	public function parse($codearray) 
	{
		$this->store = $codearray;
	}

	public function set($key, $value) 
	{
		$this->store[$key] = $value;
	}
	
	public function get($key) 
	{
		return $this->store[$key];
	}
	
}


class Config 
{
	const XML = 1;
	const INI = 2;
	const PHP = 3;

	static public function factory($config) 
	{
		switch($config) 
		{
			case self::INI:
				return new IniConfig();
			break;
			case self::XML:
				return new XmlConfig();
			break;
			case self::PHP:
				return new PhpConfig();
			break;
			default:
				return false;
		}
	}

}


/*
	// XML file
	$config = Config::factory(Config::XML);
	$config->parse('<?xml version="1.0"?><root><sth>asdsad</sth></root>');
	
	// LUA file
	$config2 = Config::factory(Config::INI);
	$config2->parse(str_replace('--', ';', file_get_contents('config.lua')));

	echo $config->get('sth');
*/
?>

